<?php

function addAutocomplete($name, $url)
{
	$autocomplete_url = site_url($url);
	$identifier = '[name="' . $name . '"]';

	echo '
		$(function() {
			$( \'' . $identifier . '\' ).autocomplete({
				source: function(request, response) {
					$.ajax({ url: "' . $autocomplete_url . '",
					data: { term: $(\'' . $identifier . '\').val()},
					dataType: "json",
					type: "POST",
					success: function(data){
						response(data);
					}
				});
			},
			minLength: 2
			});
		});
	';
}

?>